/*
 * VistaPlanificacio2.java
 *
 * Created on 30 de mayo de 2008, 3:00
 */
package vistes;

import java.awt.event.ActionListener;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author  Josep Marti
 */
public class VistaGenerada extends javax.swing.JDialog {

    private String[] headGraella = {"Hora", "Dilluns", "Dimarts", "Dimecres",
        "Dijous", "Divendres", "Dissabte", "Diumenge"
    };

    /** Creates new form VistaPlanificacio2 */
    public VistaGenerada(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    public int getIndexPlanSelected() {
        return llistaPlanificacionsV.getSelectedIndex()+1;
    }

    String getPlanSelected() {
        String pla = (String) llistaPlanificacionsV.getSelectedValue();
        return pla;
    }

    String getGraellaSelected() {
        /* Retorna un String que identifica una Emissio */
        if (!(graella.getSelectedColumn() == 0 || graella.getSelectedColumn() == -1 || graella.getSelectedRow() == -1)) {
            return (String) graella.getValueAt(graella.getSelectedRow(), graella.getSelectedColumn());
        } else {
            return null;
        }
    }

    public int getIndexsSelected() {
        return llistaPlanificacionsV.getSelectedIndex();
    }

    void setSelectPlan(int planSelected) {
        llistaPlanificacionsV.setSelectedIndex(planSelected);
    }

    void setSetmana(String setmana) {
        botoSetmana.setText(setmana);
    }

    void setPreu(double preu) {
        preuTotalV.setText("" + (float) preu);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        graella = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        llistaPlanificacionsV = new javax.swing.JList();
        botoContractar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        preuTotalV = new javax.swing.JTextField();
        butoCancelar = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        butoAnular = new javax.swing.JButton();
        butoSetmanaAnterior = new javax.swing.JButton();
        butoSetmanaSeguent = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        botoSetmana = new javax.swing.JTextPane();
        veureResum = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        graella.setModel(new javax.swing.table.DefaultTableModel(
            new Object [144][8],
            new String [] {
                "Hora","Dilluns", "Dimarts", "Dimecres", "Dijous","Divendres", "Dissabte", "Diumenge"
            }
        ));
        graella.setInheritsPopupMenu(true);
        graella.setRowSelectionAllowed(false);
        graella.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(graella);
        graella.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        jScrollPane2.setViewportView(llistaPlanificacionsV);

        botoContractar.setText("CONTRACTAR");

        jLabel3.setText("Preu Total:");

        preuTotalV.setEditable(false);

        butoCancelar.setText("Cancelar");

        jLabel4.setFont(new java.awt.Font("Bitstream Vera Sans", 1, 10));
        jLabel4.setText("Llista Planificacions");

        butoAnular.setText("Anul·lar Programa");

        butoSetmanaAnterior.setText(" << Setmana anterior");

        butoSetmanaSeguent.setText("Setmana següent >>");

        jLabel1.setText("€");

        botoSetmana.setEditable(false);
        botoSetmana.setAlignmentX(1.0F);
        botoSetmana.setAlignmentY(1.0F);
        jScrollPane3.setViewportView(botoSetmana);

        veureResum.setText("Llista");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 655, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(64, 64, 64)
                        .addComponent(butoSetmanaAnterior)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butoSetmanaSeguent)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(veureResum, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addComponent(butoCancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 117, Short.MAX_VALUE)
                        .addComponent(botoContractar))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(97, 97, 97)
                        .addComponent(jLabel4)))
                .addGap(28, 28, 28))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(preuTotalV, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 315, Short.MAX_VALUE)
                .addComponent(butoAnular)
                .addGap(414, 414, 414))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel4))
                    .addComponent(butoSetmanaAnterior)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(butoSetmanaSeguent)
                        .addComponent(veureResum)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane2)
                        .addGap(45, 45, 45)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(botoContractar)
                            .addComponent(butoCancelar)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(butoAnular)
                    .addComponent(preuTotalV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(86, 86, 86))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1056, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 572, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 568, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void setLlistaPlans(String[] llistaPlanificacions) {
        llistaPlanificacionsV.setListData(llistaPlanificacions);
    }

    public void pintarGraella(String[][] grill) {

        for (int i = 0; i < 144; i++) {
            for (int j = 0; j < 8; j++) {
                graella.setValueAt(grill[i][j], i, j);
            }
        }
    }

    public void setGraella() {
        String[][] graellaAuxiliar = new String[144][8];
        graella.setModel(new javax.swing.table.DefaultTableModel(
                graellaAuxiliar,
                new String[]{
            "Hora", "Dilluns", "Dimarts", "Dimecres", "Dijous", "Divendres", "Dissabte", "Diumenge"
        }));

    }

    public void setActions(ActionListener actions[], ListSelectionListener lPlanificacions) 
    {
        llistaPlanificacionsV.getSelectionModel().addListSelectionListener(lPlanificacions);
        butoSetmanaAnterior.addActionListener(actions[0]);
        butoSetmanaSeguent.addActionListener(actions[1]);
        butoAnular.addActionListener(actions[2]);
        botoContractar.addActionListener(actions[3]);
        veureResum.addActionListener(actions[4]);
        butoCancelar.addActionListener(actions[5]);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botoContractar;
    private javax.swing.JTextPane botoSetmana;
    private javax.swing.JButton butoAnular;
    private javax.swing.JButton butoCancelar;
    private javax.swing.JButton butoSetmanaAnterior;
    private javax.swing.JButton butoSetmanaSeguent;
    private javax.swing.JTable graella;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JList llistaPlanificacionsV;
    private javax.swing.JTextField preuTotalV;
    private javax.swing.JButton veureResum;
    // End of variables declaration//GEN-END:variables
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                VistaGenerada dialog = new VistaGenerada(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
}
